{extend name='common/common' /}

{block name="style"}
<style type="text/css">
    a:hover{
      text-decoration:underline;
      color:#ff00ff;
    }
    a{
        color：#888;!important;
    }
    .container-fluid .btn.btn-sm{
        float: right;
        margin-left: 10px;
    }
    .container-fluid{
        padding-right: 0px;
    }
    /* tr{
        cursor: pointer;
    } */
    .layui-form-item{
        margin-bottom: 0px;
    }
    .layui-form{
        display: inline-block;
    }
    .ChartTips{
        position: absolute;
        width: 100%;
        height: 470px;
        z-index: 100;
        background-color: #fff;
        text-align: center;
        line-height: 470px;
        font-size: 20px;
    }
    #markShade{
      position: fixed;
      z-index: 9999999999999;
      background-color: #000;
      opacity: 0.3;
      display: none;
      width: 100%;
      height: 100%;
    }
    #markShade h1 {
      color: #FFF;
      text-align: center;
      margin-top:300px;
    }
</style>
{/block}

{block name="content"}
<div id="markShade">
	<h1>正在导出</h1>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>订单统计</h5>
        </div>
        <div class="ibox-content">
            <!-- 新增时间  -->
            <div class="form-group" style="float: left">
                <label>日期范围：</label>
                <div class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="timeInterval" id="timeInterval" placeholder="开始 到 结束 默认为一周">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group" style="float: left">
                <label>时长：</label>
                <div class="layui-form-item" style="display: inline-block">
                    <input type="number" class="form-control" id="timeLength" name="timeLength" placeholder="默认时长一天">
                </div>
            </div>
            <a class="btn btn-primary btn-sm getIDs" id="statiSEE" style="margin-left: 20px">查  看</a>
            <div class="clear"></div>
            <div class="ChartTips">
                图表加载中:Loading...
            </div>
            <div id="main1" style="width: 100%;height:450px; min-width:400px;">

            </div>
        </div>
        <div class="ibox-content">
            <!--搜索框开始 pull-right-->
            <form id='commentForm' role="form" method="post" class="form-inline pull-left">
                <div class="content clearfix m-b">
                    <?php if(authCheck('member/director')):?>
                    <div class="form-group">
                            <label>部门：</label>
                            <select class="form-control"  name="depart_id" id="depart_id">
                                <option value="">请选择</option>
                                <?=$dep_Arr;?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>咨询师姓名：</label>
                            <select class="form-control"  name="user_id" id="user_id">
                                <option value="">请选择</option>
                                <?php foreach($departUserArr as $val):?>
                                    <option value="<?=$val['id']?>"><?=$val['real_name']?></option>>
                                <?php endforeach;?>
                            </select>
                        </div>
                    <?php endif;?>
                    <div class="form-group">
                        <label>姓名：</label>
                        <input type="text" class="form-control" id="stu_name" name="name">
                    </div>
                    <!--  2018-7-16 新增(单号/学校/专业/层次/批次)  -->
                    <!--  订单单号  -->
                    <div class="form-group">
                        <label>订单单号：</label>
                        <input type="text" class="form-control" id="order_sn" name="order_sn">
                    </div>
                    <!-- 学校 -->
                    <div class="form-group">
                        <label>学校：</label>
                        <select class="form-control"  name="school_id" id="school_id">
                            <option value="">请选择学校</option>
                            <?php foreach($schoolist as $val):?>
                                <option value="<?=$val['id']?>"><?=$val['name']?></option>>
                            <?php endforeach;?>
                        </select>
                    </div>
                    <!-- 专业 -->
                    <div class="form-group">
                        <label>专业：</label>
                        <select class="form-control"  name="major_id" id="major_id">
                            <option value="">请选择专业</option>
                        </select>
                    </div>
                    <!-- 层次 -->
                    <div class="form-group">
                        <label>层次：</label>
                        <select class="form-control"  name="grade" id="grade">
                            <option value="">请选择</option>
                            <?php foreach($gradelist as $val):?>
                                <option value="<?=$val['id']?>"><?=$val['name']?></option>>
                            <?php endforeach;?>
                        </select>
                    </div>
                    <!--  批次  -->
                    <div class="form-group">
                        <label>批次：</label>
                        <input type="text" class="form-control" id="batch" name="batch">
                    </div>



                    <!-- 新增时间  -->
                    <div class="form-group">
                        <label>日期范围：</label>
                        <div class="layui-form">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" name="KL-time" id="KL-time" placeholder="开始 到 结束">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="search"><strong>搜 索</strong>
                        </button>
                    </div>
					<!--  日/周/月/季/年   -->
					<div class="form-group">
						<button class="btn btn-default reportBtns" type="button" style="margin-top:5px" id="seaTimeDate"><strong>日 报</strong></button>
					</div>
					<div class="form-group">
						<button class="btn btn-success reportBtns" type="button" style="margin-top:5px" id="seaTimeWeek"><strong>周 报</strong></button>
					</div>
					<div class="form-group">
						<button class="btn btn-success reportBtns" type="button" style="margin-top:5px" id="seaTimeMonth"><strong>月 报</strong></button>
					</div>
					<div class="form-group">
						<button class="btn btn-success reportBtns" type="button" style="margin-top:5px" id="seaTimeQuarter"><strong>季 报</strong></button>
					</div>
					<div class="form-group">
						<button class="btn btn-success reportBtns" type="button" style="margin-top:5px" id="seaTimeYear"><strong>年 报</strong></button>
					</div>

                </div>
            </form>
            <!--搜索框结束-->
            <div class="example-wrap">
                <div class="example">
                    <table id="cusTable">
                        <thead>
                        <th class="text-center" data-width="100px" data-field="id" data-sortable="true" data-sort-name="id">订单ID <i class='fa fa-sort' id="fa-id"></i></th>
                        <th class="text-center" data-width="150px" data-field="order_sn">订单单号</th>
                        <th class="text-center" data-width="100px" data-field="c_time">创建时间</th>
                        <th class="text-center" data-width="100px" data-field="batch">批次</th>
                        <th class="text-center" data-width="100px" data-field="stu_name">姓名</th>
                        <th class="text-center" data-width="200px" data-field="school">报考学院</th>
                        <th class="text-center" data-width="100px" data-field="gradeN">层次</th>
                        <th class="text-center" data-width="200px" data-field="major">专业</th>
                        <th class="text-center" data-width="100px" data-field="acquisition_mode">学习形式</th>
                        <th class="text-center" data-width="100px" data-field="system">学制</th>
                        <th class="text-center" data-width="100px" data-field="tuition">学费</th>
                        <th class="text-center" data-width="100px" data-field="registration">报名费</th>
                        <th class="text-center" data-width="100px" data-field="material_cost">资料费</th>
                        <th class="text-center" data-width="100px" data-field="photo_collection">照片采集费</th>
                        <th class="text-center" data-width="100px" data-field="agent">经办人</th>
                        <th class="text-center" data-width="100px" data-field="consultantN">所属咨询师</th>
                        <th class="text-center" data-width="100px" data-field="depa_name">所属部门</th>

                        <!--   下面的是隐藏的   -->
                        <?php if(authCheck('statistics/kingcheck')):?>
                            <th class="text-center" data-width="100px" data-field="sex">性别</th>
                            <th class="text-center" data-width="100px" data-field="nation">民族</th>
                            <th class="text-center" data-width="100px" data-field="industry">职业</th>
                            <th class="text-center" data-width="100px" data-field="region">地区</th>
                            <th class="text-center" data-width="100px" data-field="native_place">籍贯</th>
                            <th class="text-center" data-width="190px" data-field="id_card">身份证号码</th>
                            <th class="text-center" data-width="100px" data-field="education">学历</th>
                            <th class="text-center" data-width="100px" data-field="graduate_school">毕业学校</th>
                            <th class="text-center" data-width="185px" data-field="certificate_number">证书编号</th>
                            <th class="text-center" data-width="100px" data-field="graduation_time">毕业时间</th>
                            <th class="text-center" data-width="100px" data-field="phone">联系电话</th>
                            <th class="text-center" data-width="100px" data-field="qq">QQ号</th>
                            <th class="text-center" data-width="150px" data-field="weixin">微信号</th>
                            <th class="text-center" data-width="100px" data-field="source_origin">生源途径</th>
                        <?php endif;?>
                        </thead>
                    </table>
                </div>
            </div>
            <!-- End Example Pagination -->
        </div>
    </div>
</div>
<!-- End Panel Other -->
<div id="remarks" style="display: none;padding: 15px;"></div>
<div class="laycontent" style="display: none;width: 300px;padding: 30px 15px;">
    <ul id="tree"></ul>
</div>
{/block}
{block name="script"}
<script src="__JS__/bootstrap-table-export.js"></script>
<script src="__JS__/tableExport.js"></script>
<script type="text/javascript" src="__JS__/getTime.js"></script>
<script type="text/javascript">
    //统计
    function statis() {
        var myChart = echarts.init(document.getElementById('main1'));
        // 指定图表的配置项和数据
        //ajax请求数据
        var timeInterval = $('#timeInterval').val();
        var timeLength = $('#timeLength').val();
        var pageNumber = 1;
        var pageSize = 1000;

        var stu_name = $('#stu_name').val();

        var staff = $('#staff').val();//咨询师名字
        var depart_id = $('#depart_id').val();//部门id

        if(timeLength < 0){
            layer.msg("时长不能小于0");
            return false;
        }
        $(".ChartTips").show();
        $.post("{:url('statistics/ajaxBusinStatis')}",{
            timeInterval:timeInterval,
            timeLength:timeLength,

            pageNumber:pageNumber,
            pageSize:pageSize,

            stu_name:stu_name,
            staff:staff,
            depart_id:depart_id
        },function (res) {
            if(res.code == 1){
                var option = {
                    title: {
                        text: '业务统计图'
                    },
                    tooltip : {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985'
                            }
                        }
                    },
                    legend: {
                        //线条指示
                        data:[res.kingData.name]
                    },
                    toolbox: {
                        //工具栏
                        feature: {
                            saveAsImage: {},
                            magicType: {},
                            restore: {},
                            dataView: {},
                            dataZoom: {}
                        }
                    },
                    grid: {
                        //直角坐标系内绘图网格
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis : [
                        {
                            type : 'category',
                            boundaryGap : false,
                            data : res.Xdata
                        }
                    ],
                    yAxis : [
                        {
                            type : 'value'
                        }
                    ],
                    series : [
                        {
                            name:res.kingData.name,
                            type:'line',
                            stack: '总量',
                            areaStyle: {normal: {}},
                            data:res.kingData.data,
                        },
                    ]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
                $(".ChartTips").hide();
                layer.msg(res.Msg);
            }else{
                layer.msg('图表加载失败');
            }
        })
    }
    function DoOnMsoNumberFormat(cell, row, col) {
        var result = "";
        if (row > 0 && col == 0)
            result = "\\@";
        return result;
    }
    function initTable() {
        //先销毁表格
        $('#cusTable').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#cusTable").bootstrapTable({
            method: "get",  //使用get请求到服务器获取数据
            url: "{:url('Statistics/businStatis')}", //获取数据的地址
            striped: true,  //表格显示条纹
            pagination: true, //启动分页
            pageSize: 25,  //每页显示的记录数
            pageNumber:1, //当前第几页
            pageList: [25, 100, 1000, 10000, 100000],  //记录数可选列表
            sidePagination: "server", //表示服务端请求
						resizable:true,//可变宽列表
            paginationFirstText: "首页",
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            paginationLastText: "尾页",
            queryParamsType : "undefined",
            silentSort:true,//分页记住排序
      			sortName:'id',
      			sortOrder:'desc',
            showToggle:true,
            showColumns:true,
            showRefresh: true,  //是否显示刷新按钮
            showExport: true,  //是否显示导出按钮
            // showTitle: '导出',
            // clickToSelect:true, //点击行即可选中单选/复选框
            exportDataType : "basic", //basic'导出当前页, 'all'导出全部, 'selected'导出选中项.
            exportTypes:['excel'],  //导出文件类型
            Icons:'glyphicon-export',
            exportOptions:{
                // ignoreColumn: [0,1],  //忽略某一列的索引
                fileName: '订单统计',  //文件名称设置
                worksheetName: 'sheet1',  //表格工作区名称
                tableName: '订单统计报表',
                excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
                onMsoNumberFormat: DoOnMsoNumberFormat
            },
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    stu_name  :$('#stu_name').val(),
                    c_time    :$('#KL-time').val(),
                    user_id   :$('#user_id').val(),//咨询师名字
                    depart_id :$('#depart_id').val(),//部门id
                    order_sn  :$('#order_sn').val(),//订单单号
                    school_id :$('#school_id').val(),//学校id
                    major_id  :$('#major_id').val(),//专业id
                    grade     :$('#grade').val(),//层次
                    batch     :$('#batch').val(),//批次
                    sortName  :this.sortName,
          					sortOrder :this.sortOrder
                };
                return param;
            },
            onLoadSuccess: function(res){ //加载成功时执行
                if(111 == res.code){
                    window.location.reload();
                }
                layer.msg("加载数据成功", {time : 1000});
                // var tr = '<tr><td colspan="10" class="text-right span-strong">总计</td>'
                //         + '<td class="text-center span-strong">' + res.sum + '</td></tr>';
                // $("#cusTable tbody").append(tr);
                var li = "<li data-type='all' onclick='ExportAll();'><a href='javascript:void(0)'>导出全部</a></li>";
                         $(".export>.dropdown-menu").append(li);
                         $(".export>.dropdown-menu>li:nth-child(1)>a").html('导出当前');
            },
            onLoadError: function(){  //加载失败时执行
                layer.msg("加载数据失败");
            }
            // onSort:function(name,order){ //切换排序图标
        		// 		var idName = 'fa-' + name;
        		// 		var oSort = document.getElementById(idName);
        		// 		var oFaId = document.getElementById('fa-id');
        		// 		var oFaTm = document.getElementById('fa-receivables_time');
        		// 		oFaId.className = 'fa fa-sort';
        		// 		oFaTm.className = 'fa fa-sort';
        		// 		order == 'asc'?oSort.className = 'fa fa-sort-up':oSort.className = 'fa fa-sort-down';
      			// }
        });
    }

    $(document).ready(function () {
        //调用函数，初始化表格
        initTable();
        //调用函数，初始化统计图
        statis();
        //当点击查询按钮的时候执行
        $("#search").bind("click", initTable);
        //当点击查询按钮的时候执行
        $("#statiSEE").bind("click", function(){statis();});

    });

    //时间选择
    layui.use('laydate', function() {
        var laydate = layui.laydate;
        //日期范围
        laydate.render({
            elem: '#KL-time'
            ,range: true
        });
        laydate.render({
            elem: '#timeInterval'
            ,range: true
        });
    })
	// 日/周/月/季/年报表
	$(function() {
		var seaTime = '';
		layui.use(['form','laydate'], function() {
			var form = layui.form,laydate = layui.laydate;
			laydate.render({elem: '#KL-time',range: true});
			laydate.render({elem: '#timeInterval',range: true});
		});
		//当点击查询按钮的时候执行

		$("#timeInterval").on("click",function(){
			statis();
		});

		$(".reportBtns").on('click',function(){
			$(".reportBtns").addClass('btn-success').removeClass('btn-default');
			$(this).addClass('btn-default');
		});
		//日报
		$("#seaTimeDate").on('click',function(){
			if(seaTime != ""){
				seaTime = "";
				$("#KL-time").val("");
				initTable();
			}
		});
		//周报
		$("#seaTimeWeek").on('click',function(){
			var week = getWeekStartDate() + " - " + getWeekEndDate();
			if(week != seaTime){
				seaTime = week;
				$("#KL-time").val(week);
				initTable();
			}
		});
		//月报
		$("#seaTimeMonth").on('click',function(){
			var month = getMonthStartDate() + " - " + getMonthEndDate();
			if(month != seaTime){
				seaTime = month;
				$("#KL-time").val(month);
				initTable();
			}
		});
		//季报
		$("#seaTimeQuarter").on('click',function(){
			var quarter = getQuarterStartDate() + " - " + getQuarterEndDate();
			if(quarter != seaTime){
				seaTime = quarter;
				$("#KL-time").val(quarter);
				initTable();
			}
		});
		//年报
		$("#seaTimeYear").on('click',function(){
			var year = new Date().getYear();
			year += (year < 2000) ? 1900 : 0;
			year = year + "-01-01 - " + year + "-12-31";
			if(year != seaTime){
				seaTime = year;
				$("#KL-time").val(year);
				initTable();
			}
		});
	});
	// Ajax 改变不同部门时的不同职员
    $(function(){
        $('#depart_id').on('change',function(){
            var depart_id = $('#depart_id').val();
            $.post("{:url('member/departUser')}",{
                depart_id : depart_id
            },function(res){
                if(res.code == 1){
                    var data = res.data;
                    var app = '<option value="">请选择</option>';
                    for(var i in data){
                        app += '<option value="'+data[i]["id"]+'">'+data[i]["real_name"]+'</option>'
                    }
                    $('#user_id').html(app);
                }
            })
        })
	       // Ajax 改变不同学校时的不同专业
        $('#school_id').on('change',function(){
            var school_id = $('#school_id').val();
            $.post("{:url('Statistics/ajaxMajor')}",{
                school_id : school_id
            },function(res){
              // console.log(res);
                if(res.code == 1){
                    var data = res.data;
                    var app = '<option value="">请选择</option>';
                    if(data == null || data == []){
                        $('#major_id').html(app);
                    }else{
                        for(var i in data){
                            app += '<option value="'+data[i]["id"]+'">'+data[i]["name"]+'</option>'
                        }
                        $('#major_id').html(app);
                    }
                }
            })
        })
    })
    // 导出全部
    var ExportAll = function(){
        $('#markShade').show();
        $.post("./businAllExpotr",function(res){
          setTimeout(function(){
            window.open("/upload/excel/download" + {:session("id")} + ".xls");
            $('#markShade').hide();
          },5000);
        });
    }
</script>
{/block}
